/* 
 * File:   XTimeOut.cpp
 * Author: minaev
 * 
 * Created on 25 Октябрь 2013 г., 11:38
 */

#include "XTimeOut.h"
#include "stddef.h"

XTimeOut::XTimeOut(unsigned long delay) {
    this->delay = delay;
}

XTimeOut::~XTimeOut() {
}

void XTimeOut::startTimeOut() {
    startTime = getMillisecondsTime();
}

bool XTimeOut::isTimeOut() {
    endTime = getMillisecondsTime();
    return endTime - startTime > delay;
}

void XTimeOut::setDelay(unsigned long delay){
    this->delay = delay;
}

unsigned long XTimeOut::getMillisecondsTime(){
   static struct timeval tv;
   if(gettimeofday(&tv, NULL) != 0) return 0;
   return (unsigned long)((tv.tv_sec * 1000ul) + (tv.tv_usec / 1000ul));
}